/**
 * A JavaScript array util
 *
 * @package js.lang
 * @author: DSONet (dsonet@msn.com)
 * @version $Id: JArray.js 35 2008-03-02 17:01:34Z dsonet $
 */
 /**
 * A JavaScript array util
 *
 */
var JArray = {
	indexOf : function(arr, obj, fromIndex)
	{
		if(arr.indexOf)
			return arr.indexOf(obj, fromIndex);
		fromIndex = fromIndex == null ? 0 : fromIndex < 0 ? Math.max(0, arr.length + fromIndex) : fromIndex;
		for (var i = arr.length - 1; i >= fromIndex ; i--)
			if (arr[i] === obj)
				return i;
		return - 1;
	}
	, lastIndexOf : function(arr ,obj, fromIndex)
	{
		if(arr.lastIndexOf)
			return arr.lastIndexOf(obj, fromIndex);
		fromIndex = fromIndex == null ? arr.length - 1 : fromIndex < 0 ? Math.max(0, arr.length + fromIndex) : fromIndex;
		for (var i = fromIndex; i >= 0; -- i)
			if (arr[i] === obj)
				return i;
		return - 1;
	}
	, contains : function(arr, o)
	{
		return this.indexOf(arr, o) != - 1;
	}
	, forEach : function(arr, f, obj)
	{
		if(arr.forEach)
			arr.forEach(f, obj);
		for (var i = 0, l = arr.length; i < l; i++)
			f.call(obj, arr[i], i, arr);
	}
	, filter : function(arr, f, obj)
	{
		if(arr.filter)
			return arr.filter(f, obj);
		for (var i = 0, l = arr.length, res = []; i < l; i++)
			if (f.call(obj, arr[i], i, arr))
			{
				res.push(arr[i]);
			}
		return res;
	}
	, map : function(arr, f, obj)
	{
		if(arr.map)
			return arr.map(f, obj);
		for (var i = 0, res = [], l = arr.length; i < l; i++)
			res.push(f.call(obj, arr[i], i, arr));
		return res;
	}
	, some : function(arr, f, obj)
	{
		if(arr.some)
			return arr.some(f, obj);
		for (var i = 0, l = arr.length; i < l; i++)
			if (f.call(obj, arr[i], i, arr))
			{
				return true;
			}
		return false;
	}
	, every : function(arr, f, obj)
	{
		if(arr.every)
			return arr.every(f, obj);
		for (var i = 0, l = arr.length; i < l; i++)
			if (! f.call(obj, arr[i], i, arr))
			{
				return false;
			}
		return true;
	}
};